﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CondominiosMVC.SRCuota;

namespace CondominiosMVC.Controllers
{
    public class TransaccionPagoController : Controller
    {
        //
        // GET: /TransaccionPago/

        public ActionResult Index()
        {
            String codVivienda = Request["numVivienda"];
            int numVivienda = 0;
            if (codVivienda != null)
            {
                try
                {
                    numVivienda = Convert.ToInt32(codVivienda);
                }
                catch (Exception e)
                {

                }
            }

            SRCuota.CuotasClient res = new SRCuota.CuotasClient();
            ICollection<SCuota> modelo = res.ListarCuotasPendientes(numVivienda);

            return View(modelo);
        }

        //
        // GET: /TransaccionPago/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /TransaccionPago/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /TransaccionPago/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /TransaccionPago/Edit/5

        public ActionResult Edit(int IdCuota)
        {
            SRCuota.CuotasClient res = new SRCuota.CuotasClient();
            SCuota modelo = res.ObtenerCuota(IdCuota);

            return View(modelo);
        }

        //
        // POST: /TransaccionPago/Edit/5

        [HttpPost]
        public ActionResult Edit(int IdCuota, FormCollection collection)
        {
            try
            {
                String tipoPago = (String)collection["tipoPago"];

                SRCuota.CuotasClient res = new SRCuota.CuotasClient();
                SCuota cuotaPagada = res.PagarCuota(IdCuota, tipoPago);
                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /TransaccionPago/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /TransaccionPago/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
